@*@model IEnumerable<SealManagement.Models.User>*@
	@model IEnumerable<SealManagement.Models.UserInfo>
		@{
		ViewData["Titel"] = "管理员列表";
		}


		<script src="~/js/utils.js"></script>
		<script src="~/lib/jquery/jquery-1.12.4.js"></script>
		<script src="~/lib/jquery/jquery-1.12.4.min.js"></script>
		<script>
			$(function() {
				
					console.log("@ViewBag.ValidateCode")
				console.log("@ViewBag.ValidateCode","6666666666666");
				$('#userList').on('click', '.Del', function() {
					console.log("@ViewBag.ValidateCode")
					var Id = $(this).attr('data');
					layer.open({
						type: 1,
						offset: 'auto',
						id: 'confirm',
						move: false,
						title: '确认窗口',
						scrollbar: true,
						content: '<div style="padding: 20px 40px;"> 确定删除吗？</div>',
						btn: ['确认', '取消'],
						scrollbar: false,
						resize: false,
						moveType: 1 //拖拽模式，0或者1
							,
						area: ['200px', '160px'],
						btnAlign: 'c' //按钮居中
							,
						shade: 0 //不显示遮罩
							,
						yes: function() {
							var base64 = new Base64();
							EncryptCertList((data) => {
								data = JSON.parse(data);
								let CertID = data.CertInfolist[0].CertID;
								//加密的字符串
								var str = JSON.stringify({
									Id: Id,
									validatecode:"@ViewBag.ValidateCode"
								});
								var External = {
									CertID: CertID,
									//编码
									DataBase64: base64.encode(str)
								};
								ExternalEncrypt(JSON.stringify(External), (data) => {
									data = JSON.parse(data);
									if (data.error == "Ok") {
										$.ajax({
											url: "/User/Delete",
											type: 'POST',
											data: {
												EncryptData: data.contentBase64
											},
											success: function(data) {
												if (data != null && data.state == '200') {
													layer.msg(data.message, {
														time: 500
													}, function() {
														window.location.reload();
													});

												} else {
													layer.msg(data.message);
												}
											}
										});
										layer.closeAll();
									}
								});
							})

						},
						btn2: function(index, layero) {
							//按钮【按钮二】的回调
							layer.close();
							//return false 开启该代码可禁止点击该按钮关闭
						}
					});

				});
			})
		</script>
		<h2 style="margin:20px 0">管理员列表</h2>
		<hr />
		<div class="">
			<table class="table fixed table-hover">
				<thead>
					<tr>
						<th class="text-center" style="width:100px;">
							用户名
						</th>
						<th class="text-center " style="width:100px;">
							证书序列号
						</th>
						<th class="text-center ">
							证书使用者
						</th>
						<th class="text-center " style="width:120px;">
							证书颁发者
						</th>

						<th class="text-center">
							创建日期
						</th>
						<th class="text-center ">
							备注
						</th>
						<th class="text-center ">证书开始日期</th>
						<th class="text-center ">
							证书过期日期
						</th>
						<th class="text-center ">证书</th>
						<th class="text-center ">操作</th>
					</tr>
				</thead>

				<tbody id="userList"></tbody>
			</table>
			<div style="width:100%">
				<div id="Page" style="margin:10px auto;"></div>
			</div>
		</div>

		<script>
			function down(id) {
				let base64 = new Base64();
				EncryptCertList((data) => {
					data = JSON.parse(data);
					let CertID = data.CertInfolist[0].CertID;
					//加密的字符串
					var str = JSON.stringify({
						Id: id
					});
					var External = {
						CertID: CertID,
						//编码
						DataBase64: base64.encode(str)
					};

					ExternalEncrypt(JSON.stringify(External), (data) => {
						data = JSON.parse(data);
						if (data.error == "Ok") {
							
							var d = data.contentBase64;
							var reg = new RegExp('\\+', "g")
							var dd = d.replace(reg, '%2B');
							location.href = "/User/DownCert?EncryptData=" + dd;
							
						}
					});
				})
			}

			function doSomeThing(id, url, type, href) {
				let base64 = new Base64();
				EncryptCertList((data) => {
					data = JSON.parse(data);
					let CertID = data.CertInfolist[0].CertID;
					//加密的字符串
					var str = JSON.stringify({
						Id: id
					});
					var External = {
						CertID: CertID,
						//编码
						DataBase64: base64.encode(str)
					};

					ExternalEncrypt(JSON.stringify(External), (data) => {
						data = JSON.parse(data);
						if (data.error == "Ok") {
							var dataToPost = {
								EncryptData: data.contentBase64
							};
							console.log(JSON.stringify(dataToPost));
							$.ajax({
								url: "/User/" + url,
								type: type,
								// contentType: 'application/json',
								// dataType: 'JSON',
								data: dataToPost,
								success: function(data) {
									if (data != null && data.state == '200') {
										window.location.href = href;
									} else {
										layer.msg(data.message);
										return;
									}
								},
								error: (e) => {
									console.log(e, "11")
								}
							});
						}
					});
				})
			}

			$(function() {

				$(document).ready(function() {
					//ajax请求后台数据
					getUserList(10, 1);

				});
				//$.get("/User/Detail", { id: "22" }, function (res) {
				//    console.log(res);
				//}
				//);

				var currentPage = 1;
				//数据请求
				function getUserList(PageSize, PageIndex) {
					$.ajax({
						url: "/User/Index",
						type: 'POST',
						data: {
							PageSize,
							PageIndex
						},
						success: function(result) {
							
							console.log("@ViewBag.ValidateCode","11");
							var Items = result.data;
							var total = result.total;
							showData(Items);
							pages(total);
						}
					});
				}

				// 展示数据
				function showData(Items) {
					var _html = '';
					$.each(Items, function(i) {
						var Item = Items[i];
						_html += ' <tr class="text-center ">';
						_html += '<td style="width:100px;overflow:hidden;word-break: break-all;vertical-align: middle;">' + Item.user
							.userName + '</td >';
						_html +=
							'<td style="width:130px;word-wrap:break-word;text-overflow: ellipsis;word-break: break-all;vertical-align: middle;">' +
							Item.user.arrayNo + '</td >';
						_html += '<td style="vertical-align: middle;word-wrap:break-word;" >' + Item.subject + '</td >';
						_html += '<td  style="width:150px;word-wrap:break-word;vertical-align: middle;">' + Item.issuer + '</td >';
						_html += '<td  style="vertical-align: middle;"  >' + Item.user.createDate + '</td >';
						_html += '<td  style="vertical-align: middle;" >' + Item.user.remark + '</td >';
						_html += '<td style="vertical-align: middle;" >' + Item.notBefore + '</td >';
						_html += '<td  style="vertical-align: middle;" >' + Item.notAfter + '</td >';
						_html += '<td style="width:80px;vertical-align: middle;">';
						_html += '<a onclick="down(' + Item.user.id + ')" style=" text-decoration:underline;color:blue;cursor: pointer;">点击下载</a>';
						_html += '</td > ';
						_html += '<td  style="vertical-align: middle;" >';
						_html += '<a onclick="doSomeThing(' + Item.user.id +
							',\'Detail\',\'POST\',\'/User/DetailForViewShow\')" style="cursor: pointer;">查看</a> |';
						// _html += '<a onclick="edit('+Item.user.id+')">编辑</a> |';
                        _html += '<a onclick="doSomeThing(' + Item.user.id + ',\'Edit\',\'GET\',\'/User/EditForViewShow\')" style="cursor: pointer;">编辑</a> |';
                        _html += '<a class="Del" href ="javascript:void(0)" data="' + Item.user.id + '" style="cursor: pointer;">删除</a>';
						_html += '</td ></tr> ';
					})
					$("#userList").html(_html);

				}

				// 分页条
				function pages(allNum) {
					layui.use(['laypage', 'layer'], function() {
						var laypage = layui.laypage,
							layer = layui.layer;
						laypage.render({
							elem: 'Page',
							count: allNum //数据总数，从服务端得到
								,
							limit: 10,
							curr: currentPage,
							theme: '#393D49',
							jump: function(obj, first) {
								currentPage = obj.curr;
								//首次不执行
								if (!first) {
									getUserList(10, obj.curr)
								}
							}
						});
					})
				};
			})
		</script>
